<template>
  <div class="total-container">
    <div class="common-tab-box">
      <div
        class="tab"
        v-for="item in tabName"
        :key="item.id"
        :class="{ 'active': currentSelectedId === item.id }"
        @click="handleClick(item.id)"
      >
        {{ item.text }}
      </div>
    </div>
    <component :is="tabCompName"></component>
  </div>
</template>
<script>
import starRatedHotels from './tabComp/starRatedHotels.vue'
import starRatedHomestays from './tabComp/starRatedHomestays.vue'
import travelAgency from './tabComp/travelAgency.vue'
export default {
  data() {
    return {
      tabName: [
        { text: '全市星级饭店', id: 0, compName: 'starRatedHotels' },
        { text: '全市星级民宿', id: 1, compName: 'starRatedHomestays' },
        { text: '全市旅行社', id: 2, compName: 'travelAgency' }
      ],
      currentSelectedId: 0,
      tabCompName: 'starRatedHotels'
    }
  },
  components: {
    starRatedHotels,
    starRatedHomestays,
    travelAgency
  },
  methods: {
    handleClick(id) {
      this.currentSelectedId = id
      this.tabCompName = this.tabName[id].compName
    }
  }
}
</script>
<style lang="scss" scoped>
.total-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  .common-tab-box {
    width: 100%;
    margin-left: 10px;
    .tab {
      width: 130px;
    }
  }
}
</style>
